<?php

namespace Modules\Shop\Entities\Elasticsearch;

/**
 * 商品的ES配置
 * @package Modules\Shop\Entities\Elastisearch
 */
trait GoodsElasticsearch
{
    /**
     * 是否创建索引
     * @return false
     */
    public function elasticsearchEnable()
    {
        return true;
    }

    /**
     * 最终在ES中储存的数据
     * @return mixed
     */
    public function elasticsearchArray()
    {
        return $this->only($this->elasticsearchFiels());
    }

    /**
     * 记录到ES的字段
     * @return string[]
     */
    public function elasticsearchFiels()
    {
        return [
            'title',
            'content'
        ];
    }

    /**
     * ES字段类型
     * @return string[][]
     */
    public function elasticsearchMapping()
    {
        return
            [
                'title' => [
                    'type' => 'text',
                    "analyzer" => "ik_smart"
                ],
                'content' => [
                    'type' => 'text',
                    "analyzer" => "ik_smart"
                ]
            ];
    }
}
